public class Test_7_18_1 {
    //最长回文子串:求其长度
    //"ababc"--->3
    //"abbba"---->5
    //"b"----->1
    public static void main(String[] args) {

    }
    //中心扩展算法
    public static int getLongestPalindrom(String A){
        int len = A.length();
        int ret = 0;//表示最大长度
        //当回文长度为奇数
        for (int j = 0; j < len; j++) {
            int left = j - 1;
            int right = j + 1;
            while(left >= 0 && right < len && A.charAt(left) == A.charAt(right)){
                left--;
                right++;
            }
            ret = Math.max(ret,right - left - 1);
        }
        //当回文长度为偶数
        for (int i = 0; i < len; i++) {
            int left = i;
            int right = i + 1;
            while (left >= 0 && right < len && A.charAt(left) == A.charAt(right)){
                left--;
                right++;
            }
            ret = Math.max(ret,right - left - 1);
        }
        return ret;
    }
}
